package com.springcloud.dto;

import lombok.Data;

import java.io.Serializable;

@Data
@SuppressWarnings("all")
public class Response<T> implements Serializable {
    public static final long  serialVersionUID = 1L;
    private boolean ok =false;
    private String message="fail";
    private T data;

    public Response(T data) {
        this.data=data;
    }
    public Response(){

    }
    /**
     * 成功
     * @param <T>
     * @return
     */
    public static <T> Response<T>ok(){
        return  new Response<>().success();
    }

    /**
     * 成功
     * 自定义提示信息
     * * @param message
     * @param <T>
     * @return
     */
    public static <T>Response<T> ok(String message){
        return new Response<>().success(message);

    }

    /**
     *成功
     *  返回结果
     * @param data
     * @param <T>
     * @return
     */
    public  static <T>Response<T>ok(T data){
        return new Response<>(data).success();
    }

    /**
     * 成功
     * 返回结果 & 自定义提示信息
     * * @param message
     * @param <T>
     * @return
     */
    public static <T>Response<T> ok(T data,String message){
        return new Response<>(data).success(message);
    }

    /**
     * 失败
     * * @param message
     * @param <T>
     * @return
     */
    public    <T>Response<T> fail(){
        return new Response<>().failure();
    }

    /**
     * 失败
     * 自定义提示信息
     * * @return
     */
    public  <T>Response<T> fali(String message){
        return  new Response<>().failure(message);
    }


    private Response failure(String  message) {
        this.setOk(false);
        this.setMessage(message);
        return this;
    }

    private Response failure() {
        this.setOk(false);
        this.message="fail";
        return this;

    }

    public  <T> Response success(String message) {
        this.setOk(true);
        this.setMessage(message);
        return this;
    }

    public <T> Response success() {
        this.setOk(true);
        this.message="true";
        return this;
    }

}
